#include<bits/stdc++.h>

using namespace std;

class Solution {
    public:
        int maxSatisfied(vector<int>& customers, vector<int>& grumpy, int minutes) {
            int n = customers.size();
            // init 
            int windowSum = 0;
            for(int i = 0; i < minutes; ++i){
                windowSum += customers[i] * (grumpy[i] == 1);
            }
            int ans = windowSum;
            for(int i = 1; i < (n-minutes); ++i){
                int r = i + minutes - 1;
                windowSum += customers[r] * (grumpy[r]==1) - customers[i-1] * (grumpy[i-1] == 1);
                ans = max(ans,windowSum);
            }
            for(int i = 0; i < n; ++i){
                ans += (grumpy[i] == 0) * customers[i];
            }
            return ans;
        }
    };